import java.lang.ref.SoftReference;
import java.util.Locale;

class Person {

}
public class Java16 {


    public static void main22(String[] args) {
        String str1 = "abcd";
        System.out.println(str1);

        final int[] array = {1,2,3,4};
        array[0] = 9;
        //array = new int[10];指向不能改变
    }

    public static void main21(String[] args) {
        //双引号引起来的值 就存在字符串常量池当中
        //如果有 就不存储 直接返回字符串常量池的对象即可
        String str1 = "abcd";
        //String str2 = new String("abcd");
        String str3 = "abcd";
        System.out.println(str1 == str3);

    }

    public static void main20(String[] args) {
        //删除空格(左右两边 保留中间空格)
        String str = "  hello   world  ";
        System.out.println(str);
        String ret = str.trim();
        System.out.println(ret);
    }

    public static void main19(String[] args) {
        //字符串截取
        String str = "abcdefgh";
        //返回从2位置开始截取的所有字符
        String s = str.substring(2);
        System.out.println(s);
        //返回2-6之间的所有字符
        String re = str.substring(2,6);//左闭右开[)）
        System.out.println(re);
    }

    public static void main18(String[] args) {
        //多次拆分
        String str = "name=zhangsan&age=18" ;
        String[] ret1 = str.split("&");
        for (int i = 0; i < ret1.length; i++) {
            //System.out.println(ret1[i]);
            String[] strings = ret1[i].split("=");
            for (String s : strings) {
                System.out.println(s);
            }
        }
    }

    public static void main17(String[] args) {
        String str1 = "192&168=1";
        String[] ret1 = str1.split("&|=");
        for (int i = 0; i < ret1.length; i++) {
            System.out.println(ret1[i]);
        }
    }

    public static void main16(String[] args) {
        String str1 = "192\\168\\0\\1";
        String[] ret1 = str1.split("\\\\");
        for (int i = 0; i < ret1.length; i++) {
            System.out.println(ret1[i]);
        }
    }

    public static void main15(String[] args) {
        String str1 = "192.168.0.1";
        String[] ret1 = str1.split("\\.");
        for (int i = 0; i < ret1.length; i++) {
            System.out.println(ret1[i]);
        }
    }

    public static void main14(String[] args) {
        //字符串拆分
        String str1 = "hello litter bitter";
        String[] ret1 = str1.split(" ",2);//最多分几组
        for (int i = 0; i < ret1.length; i++) {
            System.out.println(ret1[i]);
        }
    }

    public static void main13(String[] args) {
        //字符串替换
        String str1 = "ababcabcdabcde";
        String ret1 = str1.replace('a','p');
        System.out.println(ret1);

        String ret2 = str1.replace("ab","ooo");
        //如果传入字符串 其实就是向上转型
        System.out.println(ret2);

        String ret3 = str1.replaceAll("ab","666");
        System.out.println(ret3);

        String ret4 = str1.replaceFirst("ab","999");
        System.out.println(ret4);
    }

    public static void main12(String[] args) {
        //格式化
        String s = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s);
    }

    public static void main11(String[] args) {
        String str1 = "abcdef";
        char[] array = str1.toCharArray();//字符串转字符数组
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
        System.out.println();
        // 数组转字符串
        String s2 = new String(array);
        System.out.println(s2);
    }

    public static void main10(String[] args) {
        String str1 = "abcd";
        String str2 = "ABcd";
        //小写转大写
        System.out.println(str1.toUpperCase());
        //大写转小写
        System.out.println(str2.toLowerCase());
    }

    public static void main9(String[] args) {
        //字符串转化valueOf
        String str2 = String.valueOf(123);//将数字转化为字符串
        System.out.println(str2);
        String str3 = String.valueOf(new Person());
        System.out.println(str3);
        System.out.println("==========");
        String str1 = "123";
        String str4 = "12.5";
        int data = Integer.parseInt(str1);//(包装类)字符串转数字
        //基本类型对应的类类型 所以基本类型也提供了面向对象的思想
        double datat1 = Double.parseDouble(str4);
        System.out.println(datat1);
        System.out.println(data);
    }

    public static void main8(String[] args) {
        String sre = "ababcabcdabcde";
        //从后往前找字符a
        System.out.println(sre.lastIndexOf('a'));
        System.out.println(sre.lastIndexOf('a',8));
    }

    public static void main7(String[] args) {
        String sre = "ababcabcdabcde";
        //从指定位置开始找第一个c
        System.out.println(sre.indexOf('c',6));
        //在主串当中查找子串
        System.out.println(sre.indexOf("abcd"));
    }

    public static void main6(String[] args) {
        String sre = "ababcabcdabcde";
        //返回这个字符第一次出现的位置
        System.out.println(sre.indexOf('c'));
    }

    public static void main5(String[] args) {
        //字符串查找
        String sre = "hello";
        /*char ch = sre.charAt(0);
        System.out.println(ch);*/

        for (int i = 0; i < sre.length(); i++) {
            System.out.println(sre.charAt(i));//重点
        }

    }

    public static void main4(String[] args) {
        String str1 = new String("Hello");//大
        String str2 = new String("hello");
        System.out.println(str1.compareTo(str2));//比较大小
        //忽略大小写进行比较
        System.out.println(str1.compareToIgnoreCase(str2));

        System.out.println(str1.equalsIgnoreCase(str2));
    }

    public static void main3(String[] args) {
        String str1 = new String("Hello");
        String str2 = new String("hello");
        System.out.println(str1 == str2);//比较地址
        //比较两个引用所指向的对象当中内容是否相等
        System.out.println(str1.equals(str2));




    }

    public static void main2(String[] args) {
        String sre = "hello";
        System.out.println(sre.length());//这个length为方法
        int[] array = {1,2,3,4};
        System.out.println(array.length);

        String str2 = "";
        System.out.println(str2.length());
        System.out.println(str2.isEmpty());//判断空不空 如果字符串为0 返回true
        String ste3 = null;//这个引用不指向任何对象
        System.out.println("hyj".length());
    }

    public static void main1(String[] args) {
        String sre = "hello";//直接赋值
        String st2 = new String("hello");
        System.out.println(sre);
        System.out.println(st2);
        //字符数组
        char[] values = {'a','b','c','d'};
        String str3 = new String(values);//将字符数组构造成字符串
        System.out.println(str3);
    }
}
